package com.tinysand.advert.controller;

import com.alibaba.fastjson.JSON;
import com.tinysand.advert.exception.AdvertException;
import com.tinysand.advert.service.UserService;
import com.tinysand.advert.support.CreateUserRequest;
import com.tinysand.advert.support.UserCreatedResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户相关服务控制器
 *
 * Created By TINY
 * Create Time 2020/2/22
 **/
@Slf4j
@RestController
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/user")
    public UserCreatedResponse createUser(
            @RequestBody CreateUserRequest request) throws AdvertException {

        log.info("创建用户，请求对象数据（{}）", JSON.toJSONString(
                request
        ));

        return userService.createUser(request);
    }
}
